{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "21b4a9d2",
   "metadata": {},
   "source": [
    "# 1. 音频录制"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d2e33ed",
   "metadata": {},
   "source": [
    "- 安装下载\n",
    "> 1. SpeechRecognition\n",
    "> 2. Pydub\n",
    "> 3. PyAudio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "24b38187",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "beee6aef",
   "metadata": {},
   "source": [
    "# 2. 语音识别\n",
    ">1. 百度API：百度的AI账户 --（Key，secret）\n",
    ">2. I/O：input 音频文件（pcm/mav/amr）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1861ee05",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdasr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4352a13",
   "metadata": {},
   "outputs": [],
   "source": [
    "bdasr.asr('16k.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4121cfb5",
   "metadata": {},
   "outputs": [],
   "source": [
    "bdasr_result = eval(bdasr.asr('16k.wav'))['result'][0]\n",
    "bdasr_result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b925825d",
   "metadata": {},
   "source": [
    "# 3. 连接自动回复字典（openai-chatgpt）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b03acfbe",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa = [\n",
    "    \"北京科技园馆\":\"中国科学技术馆，位于北京市朝阳区北辰东路5号，东临亚运居住区，西濒奥运水系，南依奥运主体育场，北望森林公园，于1958年筹建，建设分为两期工程和新馆工程，分别于1988年9月22日、2000年4月29日、2009年9月16日开放。\"\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4067e839",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa_result = qa.get(bdasr_result)\n",
    "qa_result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2699e4d2",
   "metadata": {},
   "source": [
    "# 4. 语音合成"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e802d6f",
   "metadata": {},
   "source": [
    "> 1. 百度API：百度的AI账户（key，secret)\n",
    "> 2. I/O:input文本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44dc089f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
